package com.acme.hash;

/**
 * Shrinks dimension from [Integer.MIN_VALUE, Integer.MAX_VALUE] -&gt; [0, dimension)
 * @author Gregory Sobko
 */
public class HashConvolution implements IntHashFunction{

    private int dimension;
    private IntHashFunction hashFunction;


    public HashConvolution(IntHashFunction hashFunction) {
        this(hashFunction, 1);
    }

    public HashConvolution(IntHashFunction hashFunction, int dimension) {
        this.hashFunction = hashFunction;
        this.dimension = dimension;
    }

    public void setDimension(int dimension) {
        this.dimension = dimension;
    }

    public int getDimension() {
        return dimension;
    }

    public int hash(int value) {
        value = hashFunction.hash(value);
        return (value & 0x7FFFFFFF) % dimension;
    }
}
